package com.xjtu.platform.demander.submit.dao;


import com.xjtu.platform.answer.answer.QuestionDto;
import com.xjtu.platform.demander.submit.submitDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SubmitDao {

    @Insert("insert into requirements(request_id,user_id,mode,deadline,size,stage,question_content,description,create_time,title) values(#{request_id},#{user_id},#{mode},#{deadLine},#{size},#{stage},#{question_content},#{description},#{create_time},#{title})")
    void setSubmit(submitDto dto);

    @Select("select request_id,user_id,mode,deadline,size,stage,question_content,description,create_time,title from requirements where user_id=#{userId} order by request_id")
    List<submitDto> findSubmitById(String userId);

    @Select("select count(request_id) from requirements")
    Integer countSubmit(String userId);

    @Delete("delete from requirements where request_id=#{request_id}")
    void deleteSubmit(submitDto dto);

    @Insert("insert into questions(request_id,path,question_id,count,rank) values(#{request_id},#{path},#{question_id},#{count},0)")
    void insertQues(QuestionDto questionDto);

    @Update("update requirements set stage=#{i} where request_id=#{path}")
    void addStage(@Param("path") String path,@Param("i") Integer i);

    @Select("select stage from requirements where request_id=#{path}")
    int getStage(@Param("path") String path);

    @Select("select request_id,user_id,mode,deadline,size,stage,question_content,description,create_time,title from requirements where request_id=#{request_id}")
    submitDto searchByRequestId(String request_id);
}
